package com.ifast.activiti.test;

import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngineConfiguration;
import org.activiti.engine.ProcessEngines;
import org.apache.log4j.Logger;

import java.util.HashMap;
import java.util.Map;


public class ActivitiTable {
    public static void main(String[] args) {

        //ProcessEngine processEngine = ProcessEngineConfiguration.createProcessEngineConfigurationFromResource("activiti.cfg.xml").buildProcessEngine();

        //creatActivitiTask();
        //testStartPI();
        testFinishTask_Teacher();

    }


    public static void creatActivitiTask() {
        //加载的那两个内容就是我们之前已经弄好的基础内容哦。
        //得到了流程引擎
        ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
        processEngine.getRepositoryService()
                .createDeployment()
                .name("请假流程")
                .addClasspathResource("shengqin.bpmn")
                //  .addClasspathResource("shengqing.png")
                .deploy();
    }

    /**
     * 启动流程实例
     *    可以设置一个流程变量
     */
    public static void testStartPI(){
        /**
         * 流程变量
         *   给<userTask id="请假申请" name="请假申请" activiti:assignee="#{student}"></userTask>
         *     的student赋值
         */
        Map<String, Object> variables = new HashMap<String, Object>();
        variables.put("student", "小伍");
        ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
        processEngine.getRuntimeService()
                .startProcessInstanceById("shengqin:1:4",variables);
    }
    public static void testFinishTask_Teacher(){
        Map<String, Object> variables = new HashMap<String, Object>();
        variables.put("teacher", "我是小伍的班主任");
        ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
        processEngine.getTaskService()
                .complete("2505",variables); //完成任务的同时设置流程变量
    }
}
